import request from '@/utils/request'
import type { MenuParams, PermissionResponseData, ResponseData } from './type'

enum API {
  ALLPERMISSION_URL = '/sysPermission',
  ADDMENU_URL = '/sysPermission',
  UPDATE_URL = '/sysPermission',
  DELETEMENU_URL = '/sysPermission',
}

export const reqAllPermission = () =>
  request.get<any, PermissionResponseData>(API.ALLPERMISSION_URL)

export const reqAddOrUpdateMenu = (data: MenuParams) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATE_URL, data)
  } else {
    return request.post<any, any>(API.ADDMENU_URL, data)
  }
}

export const reqRemoveMenu = (idList: number[]) =>
  request.delete<any, ResponseData>(API.DELETEMENU_URL, { data: idList })
